package net.oschina.simpleplus.gen;

import org.apache.commons.lang3.StringUtils;

public class ProtoFieldBeanList extends ProtoFieldList {
	
	private String protoClsSimpleName;

	public ProtoFieldBeanList() {
		super();
	}

	public ProtoFieldBeanList(String name, String javaType,String protoClsSimpleName) {
		super(name, javaType);
		this.protoClsSimpleName = protoClsSimpleName;
	}

	@Override
	public StringBuffer appendBuildMethod(StringBuffer buffer) {
		return buffer.append("\n\t\t")
				.append("builder.addAll")
				.append(StringUtils.capitalize(name))
				.append("(ConvertUtil.covert2Protos(")
				.append(name)
				.append("));");
	}

	@Override
	public StringBuffer appendCopyFromMethod(StringBuffer buffer) {
		return buffer.append("\n\t\tthis.")
		.append(name)
		.append("=ConvertUtil.covert(t.get")
		.append(StringUtils.capitalize(name))
		.append("List(), new Convertor<")
		.append(protoClsSimpleName)
		.append(", ")
		.append(javaType)
		.append(">(){")
		.append("\n\t\t\t@Override")
		.append("\n\t\t\tpublic ")
		.append(javaType)
		.append(" covert(")
		.append(protoClsSimpleName)
		.append(" m){")
		.append("\n\t\t\t\t")
		.append(javaType)
		.append(" ")
		.append(StringUtils.containsWhitespace(javaType))
		.append("__n = new ")
		.append(javaType)
		.append("();")
		.append("\n\t\t\t\t")
		.append(StringUtils.containsWhitespace(javaType))
		.append("__n.copyFrom(m);")
		.append("\n\t\t\t\treturn ")
		.append(StringUtils.containsWhitespace(javaType))
		.append("__n;")
		.append("\n\t\t\t}\n\t\t});");
	}

}
